#!/bin/bash

# log目录
log_dir=./rl_daemon_logs

# 检查参数
if [ $# -eq 0 ]; then
    echo "Usage: daemon.sh [commands...]"
    exit -1
fi

# 初始化log目录
rm -rf $log_dir
mkdir -p $log_dir

# 循环
fails=0
while [ 1 ]
do

# 执行并输出
$* >> $log_dir/$(date "+%Y.%m.%d")-$fails.txt

# 失败次数增加

((fails++))
if ((fails<=8)); then
    sleep 45s
else
    sleep 5m
fi

echo Restart $fails

done